
#include <iostream>
#include <thread>
#include <functional>

#include <tenacitas_log/logger.h>
#include <tenacitas_log/text_file.h>
#include <tenacitas_log/level.h>

namespace tenacitas {
    namespace log {
        namespace test1 {


            typedef text_file_printer_factory printer_factory;

            typedef text_file_printer_factory::ptr printer_factory_ptr;

            typedef logger_factory_t<printer_factory> logger_factory;

            typedef typename logger_factory::ptr logger_factory_ptr;

            typedef typename logger_factory::logger logger;

            void wcnl( const level & p_level,
                       logger & p_log,
                       const char * p_func,
                       const char * p_file,		 
                       int64_t p_line );

            void f0( logger_factory & p_logger_factory );
      
            void f1( logger_factory & p_logger_factory );

            void f2( logger_factory & p_logger_factory );
      
            void f3( logger_factory & p_logger_factory );
      
            void f4( logger_factory & p_logger_factory );
      
            void f5( logger_factory & p_logger_factory );

            void f6( logger_factory & p_logger_factory );
      
            void f7( logger_factory & p_logger_factory );

            void f8( logger_factory & p_logger_factory );

      
            static void run( ) {
                text_file_printer_factory::ptr
                    l_text_file_printer_factory(
                        new text_file_printer_factory( "./", "test", 233 ) );
  
                logger_factory l_logger_factory( l_text_file_printer_factory );

                f6( l_logger_factory );    

                try {

                    f3( l_logger_factory );

                    std::thread l_th_1 ( f1, std::ref( l_logger_factory ) );

                    f5( l_logger_factory );
        
                    std::thread l_th_2 ( f2, std::ref( l_logger_factory ) );

                    l_th_1.join( );

                    f4( l_logger_factory );

                    l_th_2.join( );

                    f7( l_logger_factory );


                }
                catch ( std::string & l_ex ) {
                    std::cout << "exception: '" << l_ex << "'" << std::endl;
                }
                catch ( std::exception & l_ex ) {
                    std::cout << "exception: '" << l_ex.what( ) << "'" << std::endl;
                }

                f8( l_logger_factory );
            }


        }
    }
}
